import {
  FlowNodeInputTypeEnum,
  FlowNodeOutputTypeEnum,
  FlowNodeTemplateTypeEnum,
  FlowNodeTypeEnum,
  NodeInputKeyEnum,
  NodeOutputKeyEnum,
  WorkflowIOValueTypeEnum,
} from '@/types/workflow/constant';
import { FlowNodeTemplateType } from '@/types/workflow/node';

import { getHandleConfig } from '../../utils';

export const DatabaseConnectionModule: FlowNodeTemplateType = {
  id: FlowNodeTypeEnum.databaseConnection,
  templateType: FlowNodeTemplateTypeEnum.tools,
  flowNodeType: FlowNodeTypeEnum.pluginModule,
  sourceHandle: getHandleConfig(true, true, true, true),
  targetHandle: getHandleConfig(true, true, true, true),
  avatar: 'datasource.svg',
  name: '数据库连接',
  intro: '可连接常用数据库，并执行sql语句，支持MySQL和PostgreSQL。',
  showStatus: true,
  isTool: true,
  version: '481',
  isFolded: true,
  pluginId: FlowNodeTypeEnum.databaseConnection,
  inputs: [
    // Input_Template_Stream_MODE,
    {
      key: NodeInputKeyEnum.databaseType,
      renderTypeList: [FlowNodeInputTypeEnum.select, FlowNodeInputTypeEnum.reference],
      label: '数据库的类型',
      value: '',
      list: [
        {
          label: 'MySQL',
          value: 'MySQL',
        },
        {
          label: 'PostgreSQL',
          value: 'PostgreSQL',
        },
      ],
      valueType: WorkflowIOValueTypeEnum.string,
      selectedTypeIndex: 0,
      canEdit: false,
      required: true,
    },
    {
      key: NodeInputKeyEnum.host,
      renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
      label: '数据库连接host',
      value: '',
      valueType: WorkflowIOValueTypeEnum.string,
      selectedTypeIndex: 0,
      canEdit: false,
      required: true,
    },
    {
      key: NodeInputKeyEnum.port,
      renderTypeList: [FlowNodeInputTypeEnum.numberInput, FlowNodeInputTypeEnum.reference],
      label: '数据库连接端口号',
      value: '',
      valueType: WorkflowIOValueTypeEnum.number,
      selectedTypeIndex: 0,
      canEdit: false,
      required: true,
      min: 1,
      max: 65535,
    },
    {
      key: NodeInputKeyEnum.username,
      renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
      label: '用户名',
      value: '',
      valueType: WorkflowIOValueTypeEnum.string,
      selectedTypeIndex: 0,
      canEdit: false,
      required: true,
    },
    {
      key: NodeInputKeyEnum.password,
      renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
      label: '密码',
      value: '',
      valueType: WorkflowIOValueTypeEnum.string,
      selectedTypeIndex: 0,
      canEdit: false,
      required: true,
    },
    {
      key: NodeInputKeyEnum.databaseName,
      renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
      label: '数据库名称',
      value: '',
      valueType: WorkflowIOValueTypeEnum.string,
      selectedTypeIndex: 0,
      canEdit: false,
      required: true,
    },
    {
      key: NodeInputKeyEnum.sql,
      renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
      label: 'sql语句',
      value: '',
      valueType: WorkflowIOValueTypeEnum.string,
      selectedTypeIndex: 0,
      canEdit: false,
      required: true,
      description: 'sql语句，可以传入sql语句直接执行',
    },
  ],
  outputs: [
    {
      id: NodeOutputKeyEnum.result,
      key: NodeOutputKeyEnum.result,
      label: '数据库查询的结果',
      description: '返回数据库查询的结果，数据格式为Json。',
      valueType: WorkflowIOValueTypeEnum.string,
      type: FlowNodeOutputTypeEnum.static,
    },
  ],
};
